package org.gnomus.util;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import static org.gnomus.util.strings.simplify;

public class methods {

    public static Map<String, Map<String,Method>> collectMethods(Set<Class> cs) {
        Map<String, Map<String, Method>> m = new HashMap<String, Map<String, Method>>(cs.size() * 2);
        for (Class c : cs) {
            m.put(c.getSimpleName().toLowerCase(), collectMethods(c));
        }
        return m;
    }

    public static Map<String, Method> collectMethods(Class c) {
        Method[] dms = c.getDeclaredMethods();
        HashMap<String, Method> m = new HashMap<String, Method>(dms.length * 2);
        for (Method method : dms) {
            if (method.getParameterTypes().length == 0 && Modifier.isPublic(method.getModifiers())) {
                m.put(simplify(method.getName()), method);
            }
        }
        return m;
    }
}
